<?php
/**
 * wp-foundation header-extensions.php
 */
?>
<?php
// Just before the header div
function foundation_aboveheader() {
    do_action('foundation_aboveheader');
} // end foundation_aboveheader

function foundation_top_nav_above(){
global $options; foreach ($options as $value) { if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); }}
	if ($fd_nav_placement == 'Above Header'){foundation_top_nav();}
	}
add_action('foundation_aboveheader', 'foundation_top_nav_above');

// Inside the Access div
function foundation_in_header() {
    do_action('foundation_in_header');
} // end foundation_in_header

function foundation_top_nav_inside(){
global $options; foreach ($options as $value) { if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); }}
	if ($fd_nav_placement == 'Inside Header'){foundation_top_nav();}
	}
add_action('foundation_in_header', 'foundation_top_nav_inside');

// Just below the header div
function foundation_belowheader() {
    do_action('foundation_belowheader');
} // end foundation_belowheader

//foundation_aboveheader conditional options for banner
function foundation_banner_above(){
global $options; foreach ($options as $value) { if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); }}
	if ($fd_home_banner_location == 'Above Header'){foundation_home_splash();}
	}
add_action('foundation_aboveheader', 'foundation_banner_above');

function foundation_banner_below(){
global $options; foreach ($options as $value) { if (get_settings( $value['id'] ) === FALSE) { $$value['id'] = $value['std']; } else { $$value['id'] = get_settings( $value['id'] ); }}
	if ($fd_home_banner_location == 'Below Header'){foundation_home_splash();}
	if ($fd_nav_placement == 'Below Header'){foundation_top_nav();}
	}
add_action('foundation_belowheader', 'foundation_banner_below');


function foundation_pagetitle(){
	
	if ( is_single() ) { 
		$content = single_post_title('', false); 
		}       
	elseif ( is_home() || is_front_page() ) { 
		$content = bloginfo('name'); 
		$content .= print ' | '; 
		$content .= bloginfo('description'); 
		}
	elseif ( is_page() ) { 
		$content = single_post_title('', false);
		}
	elseif ( is_search() ) { 
		$content = bloginfo('name');
		$content .= print ' | Search results for ' . wp_specialchars($s); 
		$content .= get_page_number();
		}
	elseif ( is_category() ) {
		$content = __('Category Archives:', 'foundation');
		$content .= ' ' . single_cat_title("", false);;
    	}
    elseif ( is_tag() ) { 
      $content = __('Tag Archives:', 'foundation');
      $content .= ' ' . foundation_tag_query();
    	}
	elseif ( is_404() ) { 
		$content = bloginfo('name'); 
		$content .= print ' | Not Found'; 
		}
	else { 
		$content = bloginfo('name'); 
		$content .= wp_title('|'); 
		$content .= get_page_number(); 
		}
	
	echo $content;
	}

//extend the body_class functionality
add_filter('body_class','browser_body_class');
function browser_body_class($classes) {

	$browser = $_SERVER[ 'HTTP_USER_AGENT' ];
	//from thematic the super awesome framework http://themeshaper.com/
	// match comp
	if (preg_match( "/Mac/", $browser ))$classes[] = 'mac';
	elseif (preg_match( "/Windows/", $browser ))$classes[] = 'windows';
	elseif ( preg_match( "/Linux/", $browser ) )$classes[] = 'linux';
	else $classes[] = 'unknown-os';
	// match browser
	if ( preg_match( "/Chrome/", $browser ) ) {
			$classes[] = 'chrome';
			preg_match( "/Chrome\/(\d.\d)/si", $browser, $matches);
			$classesh_version = 'ch' . str_replace( '.', '-', $matches[1] );      
			$classes[] = $ch_version;

	} elseif ( preg_match( "/Safari/", $browser ) ) {
			$classes[] = 'safari';
			preg_match( "/Version\/(\d.\d)/si", $browser, $matches);
			$sf_version = 'sf' . str_replace( '.', '-', $matches[1] );      
			$classes[] = $sf_version;
			
	} elseif ( preg_match( "/Opera/", $browser ) ) {
			$classes[] = 'opera';
			preg_match( "/Opera\/(\d.\d)/si", $browser, $matches);
			$op_version = 'op' . str_replace( '.', '-', $matches[1] );      
			$classes[] = $op_version;
			
	} elseif ( preg_match( "/MSIE/", $browser ) ) {
			$classes[] = 'msie';
			if( preg_match( "/MSIE 6.0/", $browser ) ) {
					$classes[] = 'ie6';
			} elseif ( preg_match( "/MSIE 7.0/", $browser ) ){
					$classes[] = 'ie7';
			} elseif ( preg_match( "/MSIE 8.0/", $browser ) ){
					$classes[] = 'ie8';
			}
			
	} elseif ( preg_match( "/Firefox/", $browser ) && preg_match( "/Gecko/", $browser ) ) {
			$classes[] = 'firefox';
			preg_match( "/Firefox\/(\d)/si", $browser, $matches);
			$ff_version = 'ff' . str_replace( '.', '-', $matches[1] );      
			$classes[] = $ff_version;
			
	} else {
			$classes[] = 'unknown-browser';
	}

	if(is_single()) {
	$category = get_the_category();
	$classes[] .= $category[0]->slug;
	$tag = get_tags();
	$classes[] .= $tag[0]->slug;
}
	
	return $classes;
}


// The header function and its populating functions
function foundation_header() {
    do_action('foundation_header');
}

		function foundation_title_description_wrap_open() { ?>
			<div id="title-description-wrap">
		<?php }
		add_action('foundation_header','foundation_title_description_wrap_open',1);
		
		
		function foundation_site_title() { ?>
			<div id="site-title">
            	<span>
                	<a href="<?php bloginfo('url') ?>/" title="<?php bloginfo('name') ?>" rel="home"><?php bloginfo('name') ?></a>
                </span>
            </div>
		<?php }
		add_action('foundation_header','foundation_site_title',3);
		

		function foundation_site_description() {
			if (is_home() || is_front_page()) { ?>
			<h1 id="site-description"><?php bloginfo('description') ?></h1>
			<?php } else { ?>	
			<div id="site-description"><?php bloginfo('description') ?></div>
			<?php }
		}
		add_action('foundation_header','foundation_site_description',5);
		

		function foundation_title_description_wrap_close() { ?>
		    	</div><!--  .eof title-description-wrap -->
		<?php }
		add_action('foundation_header','foundation_title_description_wrap_close',7);
// END OF: The header function and its populating functions
			
		function foundation_top_navigation(){			
			?><div id="dynamic-top-nav-wrap">
				<div class="skip-link">
                	<a href="#content" title="<?php _e( 'Skip to content', 'foundation' ) ?>"><?php _e( 'Skip to content', 'foundation' ) ?></a>
                </div>
			<?php foundation_in_header(); ?>
			</div><!-- .eof top-navigation -->
			<?php 
		}
		add_action('foundation_header','foundation_top_navigation',9);

?>